package com.fxl.majiang.message.output;

import com.fxl.majiang.enums.PlayerStatusEnum;
import com.fxl.majiang.room.Player;
import lombok.Data;

/**
 * @author fengxinglei
 * @date 2022/8/17 13:59
 * @description TODO
 */
@Data
public class OutputJoinMsgData implements OutputMessageData {
    private static final long serialVersionUID = -4717651365581846885L;

    // 自己
    private JoinedUser selfInfo;

    // 上家
    private JoinedUser previousInfo;

    // 下家
    private JoinedUser nextInfo;

    // 对家
    private JoinedUser oppositeInfo;

    public void setSelfInfo(String name, Player player) {
        this.selfInfo = new JoinedUser(name, player);
    }
    public void setPreviousInfo(String name, Player player) {
        if (player != null) {
            this.previousInfo = new JoinedUser(name, player);
        }
    }

    public void setNextInfo( String name, Player player) {
        if (player != null) {
            this.nextInfo = new JoinedUser(name, player);
        }
    }

    public void setOppositeInfo(String name, Player player) {
        if (player != null) {
            this.oppositeInfo = new JoinedUser(name, player);
        }
    }


    @Data
    public class JoinedUser {
        private String userId;

        private String name;

        /**
         * 座位
         * @see com.fxl.majiang.enums.SeatEnum
         */
        private int seat;

        private Boolean isReady;

        public JoinedUser(String name, Player player) {
            this.userId = player.getUserId();
            this.name = name;
            this.seat = player.getSeat().getCode();
            this.isReady = player.getPlayStatus() == PlayerStatusEnum.READY;
        }
    }
}
